<?php
/**
 * Created by PhpStorm.
 * User: william
 * Date: 16-8-31
 * Time: 下午2:44
 */
namespace V5;
class C_RefundOrderList extends \ResourceClass {
    public $isActive = true;
    public $remark = '退单列表';

    public function get(array $req, array $post, &$result){
        try {
            /* 授权验证【开始】 */
            if (!isset($req['uid'])) {
                return 'require user id ';
            }
            if (!isset($req['userType'])) {
                return 'require user type';
            }
            if (!isset($req['k']) || !isset($req['t'])) {
                return 'data error';
            }
            $customer_handler = new \Biz\UserHandler();
            $customer_cls = $customer_handler ->getById($req['userType'],$req['uid']);
            if(!is_object($customer_cls) && $customer_cls->getEnterpriseId() ==false){
                return 'data error';
            }
            $enterprise_id = $customer_cls ->getEnterpriseId();
            if (\Biz\UserHandler::checkAuth($req['userType'],$req['uid'],$enterprise_id,$req['t'],$req['k']) == false) {
                return 'data illegal';
            }
            /* 授权验证【结束】 */
            if(!array_key_exists('uid',$req)||empty($req['uid'])){
                return 'require uid';//买家id
            }
            $l = isset($req['l']) ? $req['l'] : 100000;
            $o = isset($req['o']) ? $req['o'] : 0;
            // 实例化列表类
            $tabulation = new \Cls\Tabulation();
            // 初始化列表类相关参数
            if(array_key_exists('ordercode',$req)&&!empty($req['ordercode'])){
                $tabulation->setWhere('ordercode', $req['ordercode']);
            }
            $tabulation->setWhere('enterprise_id', $enterprise_id)
                ->setWhere('customer_id', $req['uid'])
                ->setOffset($o)
                ->setLimit($l)
                ->setOrderBy('id', 'desc');
            $refundorder_handler = new \Biz\RefundOrderHandler();
            $refundorder_handler->getRefundOrderListByEnterpriseId($tabulation);
            $refundorder_info = array();
            if($tabulation->getSuccessStatus()){
                foreach($tabulation->getData() as $refund_order_cls){
                    $refund_order_tmp = array();
                    $refund_order_tmp['id'] = $refund_order_cls->getId();
                    $refund_order_tmp['ordercode'] = $refund_order_cls->getRefundOrderCode();
                    $refund_order_tmp['enterprise_id'] = $refund_order_cls->getEnterpriseId();
                    $refund_order_tmp['enterprise_customer_id'] = $refund_order_cls->getEnterpriseCustomerId();
                    $refund_order_tmp['status'] = $refund_order_cls->getStatusStr();
                    $refund_order_tmp['refund_sku_price'] = $refund_order_cls->getRefundPrice();
                    if(is_object($refund_order_cls->getCustomerInfo()) && $refund_order_cls->getCustomerInfo() != false){
                        $refund_order_tmp['contact'] = $refund_order_cls->getCustomerInfo()->getContact();
                    }
                    $refund_order_detail = $refund_order_cls->getOrderDetail();
                    if(!array_key_exists('refund_sku_amout',$refund_order_tmp)){
                        $refund_order_tmp['refund_sku_amout'] = '';
                    }
                    if(!array_key_exists('refund_sku_price',$refund_order_tmp)){
                        $refund_order_tmp['refund_sku_price'] = '';
                    }
                    if($refund_order_detail){
                        foreach($refund_order_detail as $refund_order_detail_cls){
                            $refund_order_tmp['refund_sku_amout'] += $refund_order_detail_cls->getRefundSkuAmout();
                        }
                    }
                    $refund_order_tmp['insert_time'] = $refund_order_cls->getCreateAt();
                    $refund_order_tmp['pay_refund_status'] = $refund_order_cls->getPayRefundStatusStr();
                    $refund_order_tmp['delivery_refund_status'] = $refund_order_cls->getDeliveryRefundStatusStr();
                    $refundorder_info['lists'][] = $refund_order_tmp;
                }
            }
            $total = $tabulation->getTotal();
            $refundorder_info['total'] = $total;
            $result = $refundorder_info?$refundorder_info:array();
        } catch (Exception $e) {
            return $e->getMessage();
        }

    }

}